﻿using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace ToyundaPhone.Controls
{
	public partial class SongSearchControl : UserControl, System.ComponentModel.INotifyPropertyChanged
	{
		public event EventHandler TextChanged;

		public SongSearchControl()
		{
			InitializeComponent();
		}

		private void SearchBox_TextChanged(object sender, TextChangedEventArgs e)
		{
			OnTextChanged();
			OnNotifyPropertyChanged("Text");
		}

		protected virtual void OnTextChanged()
		{
			if (TextChanged != null)
			{
				TextChanged(this, new EventArgs());
			}
		}

		public string Text
		{
			get
			{
				return SearchBox.Text;
			}
		}

		public string ApplicationName
		{
			get { return (string)GetValue(ApplicationNameProperty); }
			set { SetValue(ApplicationNameProperty, value); }
		}

		// Using a DependencyProperty as the backing store for ApplicationName.  This enables animation, styling, binding, etc...
		public static readonly DependencyProperty ApplicationNameProperty =
			DependencyProperty.Register("ApplicationName", typeof(string), typeof(SongSearchControl), new PropertyMetadata("APPLICATION NAME"));

		public string Hint
		{
			get { return (string)GetValue(HintProperty); }
			set { SetValue(HintProperty, value); }
		}

		// Using a DependencyProperty as the backing store for Hint.  This enables animation, styling, binding, etc...
		public static readonly DependencyProperty HintProperty =
			DependencyProperty.Register("Hint", typeof(string), typeof(SongSearchControl), new PropertyMetadata("rechercher"));

		public Style HintStyle
		{
			get { return (Style)GetValue(HintStyleProperty); }
			set { SetValue(HintStyleProperty, value); }
		}

		// Using a DependencyProperty as the backing store for HintStyle.  This enables animation, styling, binding, etc...
		public static readonly DependencyProperty HintStyleProperty =
			DependencyProperty.Register("HintStyle", typeof(Style), typeof(SongSearchControl), new PropertyMetadata(null));

		public InputScope InputScope
		{
			get { return (InputScope)GetValue(InputScopeProperty); }
			set { SetValue(InputScopeProperty, value); }
		}

		// Using a DependencyProperty as the backing store for InputScope.  This enables animation, styling, binding, etc...
		public static readonly DependencyProperty InputScopeProperty =
			DependencyProperty.Register("InputScope", typeof(InputScope), typeof(SongSearchControl), new PropertyMetadata(null));

		private void SearchBox_KeyUp(object sender, KeyEventArgs e)
		{
			if (e.Key == Key.Enter)
			{
				e.Handled = true;
				(Application.Current.RootVisual as Microsoft.Phone.Controls.PhoneApplicationFrame).Focus();
			}
		}

		#region INotifyPropertyChanged Members

		public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;

		#endregion

		protected void OnNotifyPropertyChanged(string propertyName)
		{
			if (PropertyChanged != null)
			{
				PropertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));
			}
		}
	}
}